﻿@using System.Data;
@using DTcms.Common;
@using DTcms.Model;
@{
    ViewBag.Title = "";
    siteconfig siteConfig = ViewBag.siteConfig;
    List<DTcms.Model.article_attribute_field> sysFieldList = ViewBag.sysFieldList;
    List<DTcms.Model.article_attribute_field> otherFieldList = ViewBag.otherFieldList;
    DTcms.Model.site_channel channelModel = ViewBag.channelModel;
    int channel_id = channelModel.id;
    bool Is_Edit = (ViewBag.action == "Edit" || ViewBag.action == "Copy") ? true : false;//判断是否是修改
}
@model DTcms.Model.article
@section HeaderContent{
    <script type="text/javascript" charset="utf-8" src="~/scripts/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="~/scripts/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="~/scripts/ueditor/lang/zh-cn/zh-cn.js"></script>
}
<form id="form1" class="layui-form" url="ArticleSave?action=@ViewBag.action&id=@ViewBag.id&channel_id=@channel_id">
    @Html.AntiForgeryToken()
    <!--导航栏-->
    <div class="pageheader">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="../article/article_list?channel_id=@channel_id" class="back"><i class="fa fa-mail-reply-all"></i> 返回列表页</a></li>
                <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
                <li><a href="../article/article_list?channel_id=@channel_id">内容管理</a> </li>
                <li><a href="javascript:;">编辑内容</a> </li>
            </ul>
        </div>
    </div>
    <!--/导航栏-->
    <!--内容-->
    <div class="layui-fluid">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title" id="floatHead">
                <li class="layui-this">基本信息</li>
                @if (otherFieldList.Count > 0)
                {
                    <li>扩展选项</li>
                }
                <li>详细描述</li>
                @if (channelModel.is_attribute == 1)
                {
                    <li>自定义参数</li>
                }
                <li>SEO选项</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属类别</label>
                        <div class="layui-input-block">
                            <select class="select" name="category_id" url="/webapi/categoryJson?id=@channel_id" selectValue="@Model.category_id" promtion="请选择类别..." datatype="*" sucmsg=" "><option value="">请选择类别...</option></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否发布</label>
                        <div class="layui-input-block">
                            @Html.RadioButton("status", 0, Model.status == 0, new { title = "是" })
                            @Html.RadioButton("status", 1, Model.status == 1, new { title = "否" })
                            <span class="Validform_checktip">*不发布前台则无法显示</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">推荐类型</label>
                        <div class="layui-input-block layui-rule-multi-checkbox">
                            @Html.CheckBox("is_msg", Model.is_msg == 1, new { title = "允许评论" })
                            @Html.CheckBox("is_top", Model.is_top == 1, new { title = "置顶" })
                            @Html.CheckBox("is_red", Model.is_red == 1, new { title = "推荐" })
                            @Html.CheckBox("is_hot", Model.is_hot == 1, new { title = "热门" })
                            @Html.CheckBox("is_slide", Model.is_slide == 1, new { title = "幻灯片" })
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容标题</label>
                        <div class="layui-input-block">
                            @Html.TextBox("title", Model.title, new { @class = "input normal", datatype = "*2-100", sucmsg = " " })
                            <span class="Validform_checktip">*标题最多100个字符</span>
                        </div>
                    </div>
                    @{
                        var findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "sub_title"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_sub_title", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input normal", datatype = "*0-255", sucmsg = " " })
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                    }
                    <div class="layui-form-item">
                        <label class="layui-form-label">Tags标签</label>
                        <div class="layui-input-block">
                            @Html.TextBox("tags", Model.tags, new { @class = "input normal" })
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">封面图片</label>
                        <div class="layui-input-block">
                            @Html.TextBox("img_url", Model.img_url, new { @class = "input normal upload-path" })
                            <div class="upload-box choose-pick"><a href="javascript:;" class="webuploader-pick" title="图片空间">选择图片</a></div>
                            <div class="upload-box upload-cover"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">&nbsp;</label>
                        <div class="layui-input-block">
                            <input type="checkbox" id="autoImg" name="autoImg" title="自动提取内容第一张图片为缩略图">
                        </div>
                    </div>
                    @{
                        <!-- 商品货号 -->
                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "goods_no"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_goods_no", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input normal", datatype = "*0-100", sucmsg = " " })
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                        <!-- /商品货号 -->
                    }
                    @{
                        <!-- 库存数量 -->
                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "stock_quantity"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_stock_quantity", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input small", datatype = "n", sucmsg = " " })
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                        <!-- /库存数量 -->
                    }
                    @{
                        <!-- 市场价格 -->
                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "market_price"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_market_price", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input small", datatype = @"/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/", sucmsg = " " }) 元
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                        <!-- /市场价格 -->
                    }
                    @{
                        <!-- 销售价格 -->
                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "sell_price"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_sell_price", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input small", datatype = @"/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/", sucmsg = " " }) 元
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                        <!-- /销售价格 -->
                    }
                    @{
                        <!-- 积分 -->
                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "point"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_point", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input small", datatype = @"/^-?\d+$/", sucmsg = " " })
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                        <!-- /积分 -->
                    }
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序数字</label>
                        <div class="layui-input-block">
                            @Html.TextBox("sort_id", Model.sort_id, new { @class = "input small", datatype = "n", sucmsg = " " })
                            <span class="Validform_checktip">*数字，越小越向前</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">浏览次数</label>
                        <div class="layui-input-block">
                            @Html.TextBox("click", Model.click, new { @class = "input small", datatype = "n", sucmsg = " " })
                            <span class="Validform_checktip">点击浏览该信息自动+1</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block">
                            @Html.TextBox("add_time", Model.add_time.ToString("yyyy-MM-dd HH:mm:ss"), new { @class = "input rule-date-input", datatype = @"/^\s*$|^\d{4}\-\d{1,2}\-\d{1,2}\s{1}(\d{1,2}:){2}\d{1,2}$/", errormsg = "请选择正确的日期", sucmsg = " " })
                            <span class="Validform_checktip">不选择默认当前发布时间</span>
                        </div>
                    </div>
                    @if (channelModel != null && channelModel.is_albums == 1)
                    {
                        <div class="layui-form-item">
                            <label class="layui-form-label">图片相册</label>
                            <div class="layui-input-block">
                                <div class="upload-box upload-album"></div>
                                <input type="hidden" name="hidFocusPhoto" id="hidFocusPhoto" class="focus-photo" />
                                <div class="photo-list">
                                    <div class="photo-ul">
                                        @if (Model.albums != null)
                                        {
                                            int albums_loop_id = 0;
                                            foreach (DTcms.Model.article_albums item in Model.albums)
                                            {
                                                <div class="photo-li">
                                                    <input type="hidden" name="hid_photo_name" value="@item.id|@item.original_path|@item.thumb_path" />
                                                    <input type="hidden" name="hid_photo_remark" value="@item.remark" />
                                                    <input type="hidden" name="hid_photo_sort" class="hid_photo_sort" value="@item.sort_id" />
                                                    <div class="img-box" onclick="setFocusImg(this);">
                                                        <img src="@item.thumb_path" bigsrc="@item.original_path" />
                                                        <span class="remark"><i>@(item.remark == "" ? "暂无描述..." : item.remark)</i></span>
                                                    </div>
                                                    <a href="javascript:;" onclick="setRemark(this);">描述</a>
                                                    <a href="javascript:;" onclick="delImg(this);">删除</a>
                                                    <a href="javascript:;" class="viewImg" onclick="ajaxLoadImg(@albums_loop_id);">浏览</a>
                                                    <a href="javascript:;" onclick="onOrder(this, -1);" class="pre" title="前移"><i class="layui-icon layui-icon-prev"></i></a>
                                                    <a href="javascript:;" onclick="onOrder(this, 1);" class="next" title="后移"><i class="layui-icon layui-icon-next"></i></a>
                                                </div>
                                                albums_loop_id++;
                                            }
                                        }
                                    </div>
                                </div>
                            </div>
                        </div>
                    }
                    @if (channelModel != null && channelModel.is_attach == 1)
                    {
                        <div class="layui-form-item">
                            <label class="layui-form-label">上传附件</label>
                            <div class="layui-input-block">
                                <a class="layui-btn layui-btn-primary icon-btn attach-btn"><i class="iconfont icon-add"></i> 添加附件</a>
                                <div id="showAttachList" class="attach-list">
                                    <div class="attach-ul">
                                        @if (Model.attach != null)
                                        {
                                            foreach (var item in Model.attach)
                                            {
                                                <div class="attach-li">
                                                    <input name="hid_attach_id" type="hidden" value="@item.id" />
                                                    <input name="hid_attach_filename" type="hidden" value="@item.file_name" />
                                                    <input name="hid_attach_filepath" type="hidden" value="@item.file_path" />
                                                    <input name="hid_attach_filesize" type="hidden" value="@item.file_size" />
                                                    <i class="iconfont icon-attachment"></i>
                                                    <a href="javascript:;" onclick="delAttachNode(this);" class="del" title="删除附件"><i class="iconfont icon-remove"></i></a>
                                                    <a href="javascript:;" onclick="showAttachDialog(this);" class="edit" title="更新附件"><i class="iconfont icon-pencil1"></i></a>
                                                    <div class="title">@item.file_name</div>
                                                    <div class="info">
                                                        类型：<span class="ext">@item.file_ext</span> 大小：
                                                        <span class="size">
                                                            @Utils.CountSize(item.file_size)
                                                        </span> 下载：<span class="down">@item.down_num</span>次
                                                    </div>
                                                    <div class="btns">下载积分：<input type="text" name="txt_attach_point" onkeydown="return checkNumber(event);" value="@item.point" /></div>
                                                </div>
                                            }
                                        }
                                    </div>
                                </div>
                            </div>
                        </div>
                    }
                </div>
                <!-- 扩展选项 -->
                @if (otherFieldList.Count > 0)
                {
                    <div class="layui-tab-item">
                        @{
                            findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "user_id"; });
                            if (findItem != null)
                            {
                                <div class="layui-form-item">
                                    <label class="layui-form-label">@findItem.title</label>
                                    <div class="layui-input-block">
                                        @Html.TextBox("field_control_user_id", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input small", datatype = "n", sucmsg = " " })
                                        @(Is_Edit && Model.fields.ContainsKey(findItem.name) ? Html.get_user_nick_name(Utils.StrToInt(Model.fields[findItem.name])) : "")
                                        <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                    </div>
                                </div>
                            }
                            findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "provinceid"; });
                            if (findItem != null)
                            {
                                <div class="layui-form-item">
                                    <label class="layui-form-label">省市区县</label>
                                    <div class="layui-input-block">
                                        <select class="select" name="field_control_provinceid" url="/admin_ajax/layui_region_list" child="field_control_cityid" childDataPath="/admin_ajax/layui_region_list" selectValue="@(Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value)" promtion="请选择省...">
                                            <option value="">请选择省...</option>
                                        </select>
                                        @{
                                            findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "cityid"; });
                                            if (findItem != null)
                                            {
                                                <select class="select" name="field_control_cityid" url="/admin_ajax/layui_region_list" child="field_control_areaid" childDataPath="/admin_ajax/layui_region_list" selectValue="@(Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value)" promtion="请选择市...">
                                                    <option value="">请选择市...</option>
                                                </select>
                                            }
                                            findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "areaid"; });
                                            if (findItem != null)
                                            {
                                                <select class="select" name="field_control_areaid" url="/admin_ajax/layui_region_list" child="field_control_jiedaoid" childDataPath="/admin_ajax/layui_region_list" selectValue="@(Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value)" promtion="请选择区县...">
                                                    <option value="">请选择区县...</option>
                                                </select>
                                            }
                                            findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "jiedaoid"; });
                                            if (findItem != null)
                                            {
                                                <select class="select" name="field_control_jiedaoid" selectValue="@(Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value)" promtion="请选择街道、乡...">
                                                    <option value="">请选择街道、乡...</option>
                                                </select>
                                            }
                                        }
                                    </div>
                                </div>
                            }
                            findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "map_x"; });
                            if (findItem != null)
                            {
                                <div class="layui-form-item">
                                    <label class="layui-form-label">地图经纬度</label>
                                    <div class="layui-input-inline">
                                        @Html.TextBox("field_control_map_x", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input short" })
                                    </div>
                                    @{
                                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "map_y"; });
                                        if (findItem != null)
                                        {
                                            <div class="layui-input-inline">
                                                @Html.TextBox("field_control_map_y", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input short" })
                                            </div>
                                        }
                                    }
                                    <div class="layui-input-inline">
                                        <a class="layui-btn layui-btn-primary icon-btn" id="btnMap"><i class="layui-icon">&#xe715;</i>位置选择</a>
                                    </div>
                                </div>
                            }
                        }
                        @foreach (DTcms.Model.article_attribute_field item in otherFieldList)
                        {
                            switch (item.control_type)
                            {
                                case "single-text"://单行文本
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">@item.title</label>
                                        <div class="layui-input-block">
                                            @{
                                                IDictionary<string, object> attr1 = new Dictionary<string, object>();
                                                //CSS样式及TextMode设置
                                                if (item.control_type == "single-text") //单行
                                                {
                                                    attr1.Add("class", "input normal");
                                                }
                                                else if (item.control_type == "multi-text") //多行
                                                {
                                                    attr1.Add("class", "input");
                                                }
                                                else if (item.control_type == "number") //数字//String.Compare
                                                {
                                                    attr1.Add("class", "input small");
                                                }
                                                else if (item.control_type == "datetime") //时间日期
                                                {
                                                    attr1.Add("class", "input rule-date-input");
                                                }
                                                else if (item.control_type == "images" || item.control_type == "video") //图片视频
                                                {
                                                    attr1.Add("class", "input normal upload-path");
                                                }
                                                if (!string.IsNullOrEmpty(item.valid_tip_msg))
                                                {
                                                    attr1.Add("tipmsg", item.valid_tip_msg);
                                                }
                                                if (!string.IsNullOrEmpty(item.valid_error_msg))
                                                {
                                                    attr1.Add("errormag", item.valid_error_msg);
                                                }
                                                if (!string.IsNullOrEmpty(item.valid_pattern))
                                                {
                                                    attr1.Add("datatype", item.valid_pattern);
                                                    attr1.Add("sucmsg", " ");
                                                }

                                                if (item.is_required == 1 && string.IsNullOrEmpty(item.valid_pattern))
                                                {
                                                    if (item.control_type == "number")
                                                    {
                                                        if (item.data_place == 0)
                                                        {
                                                            attr1.Add("datatype", "n");
                                                        }
                                                        else
                                                        {
                                                            attr1.Add("datatype", @"/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1," + item.data_place + "})?$/");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        attr1.Add("datatype", "*");
                                                    }
                                                    attr1.Add("sucmsg", " ");
                                                }

                                                if (item.control_type == "single-text")
                                                {
                                                    //是否密码框
                                                    if (item.is_password == 1)
                                                    {
                                                        @Html.Password("field_contorl_" + item.name, Is_Edit ? Model.fields[item.name] : item.default_value, attr1)
                                                    }
                                                    else
                                                    {
                                                        @Html.TextBox("field_control_" + item.name, Is_Edit ? Model.fields[item.name] : item.default_value, attr1)
                                                    }
                                                }
                                                else if (item.control_type == "datetime")
                                                {
                                                    @Html.TextBox("field_control_" + item.name, Is_Edit ? Utils.StrToDateTime(Model.fields[item.name]).ToString("yyyy-MM-dd HH:mm:ss") : item.default_value, attr1)
                                                }
                                                else if (item.control_type == "multi-text")
                                                {
                                                    @Html.TextArea("field_control_" + item.name, Is_Edit ? Model.fields[item.name] : item.default_value, attr1)
                                                }
                                                else
                                                {
                                                    @Html.TextBox("field_control_" + item.name, Is_Edit ? Model.fields[item.name] : item.default_value, attr1)
                                                }
                                            }
                                            @{
                                                //如果是图片则添加上传按钮
                                                if (item.control_type == "images")
                                                {
                                                    <div class="upload-box choose-pick"><a href="javascript:;" class="webuploader-pick" title="图片空间">选择图片</a></div>
                                                    <div class="upload-box upload-img"></div>
                                                }
                                                //如果是视频则添加上传按钮
                                                if (item.control_type == "video")
                                                {
                                                    <div class="upload-box upload-video"></div>
                                                    <a class="layui-btn layui-btn-primary icon-btn" href="javascript:;" id="video_view"><i class="iconfont icon-eye1"></i>观看</a>
                                                }
                                            }
                                            <span class="Validform_checktip">@item.valid_tip_msg</span>
                                        </div>
                                    </div>
                                    if (item.control_type == "video")
                                    {
                                        <div class="layui-form-item">
                                            <label class="layui-form-label"></label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" id="videoImg" name="videoImg" title="选取上传的视频作为封面" />
                                                <span class="Validform_checktip">优先级高</span>
                                            </div>
                                        </div>
                                    }
                                    break;
                                case "multi-text": //多行文本
                                    goto case "single-text";
                                case "editor": //编辑器
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">@item.title</label>
                                        <div class="layui-input-block">
                                            @{
                                                IDictionary<string, object> attr3 = new Dictionary<string, object>();
                                                if (item.editor_type == 1)
                                                {
                                                    attr3.Add("class", "editor-mini");
                                                }
                                                else
                                                {
                                                    attr3.Add("class", "editor");
                                                }
                                                if (!string.IsNullOrEmpty(item.valid_tip_msg))//验证提示信息
                                                {
                                                    attr3.Add("tipmsg", item.valid_tip_msg);
                                                }
                                                if (!string.IsNullOrEmpty(item.valid_error_msg))//验证失败提示信息
                                                {
                                                    attr3.Add("errormag", item.valid_error_msg);
                                                }
                                                if (!string.IsNullOrEmpty(item.valid_pattern))//验证表达式
                                                {
                                                    attr3.Add("datatype", item.valid_pattern);
                                                    attr3.Add("sucmsg", " ");
                                                }
                                                @Html.TextArea("field_control_" + item.name, Is_Edit ? Model.fields[item.name] : item.default_value, attr3)
                                            }
                                            <span class="Validform_checktip">@item.valid_tip_msg</span>
                                        </div>
                                    </div>
                                    break;
                                case "images": //图片上传
                                    goto case "single-text";
                                case "video": //视频上传
                                    goto case "single-text";
                                case "number": //数字
                                    goto case "single-text";
                                case "datetime": //时间日期
                                    goto case "single-text";
                                case "checkbox"://复选框
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">@item.title</label>
                                        <div class="layui-input-block">
                                            @Html.CheckBox("field_control_" + item.name, (Is_Edit ? Model.fields[item.name] : item.default_value) == "1", new { title = "是" })
                                            @if (!string.IsNullOrEmpty(item.valid_tip_msg))
                                            {
                                                <span class="Validform_checktip">@item.valid_tip_msg</span>
                                            }
                                        </div>
                                    </div>
                                    break;
                                case "multi-radio"://多项单选
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">@item.title</label>
                                        <div class="layui-input-block">
                                            @{
                                                string[] valArr = item.item_option.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                                                for (int i = 0; i < valArr.Length; i++)
                                                {
                                                    string[] valItemArr = valArr[i].Split('|');
                                                    if (valItemArr.Length == 2)
                                                    {
                                                        bool selected = false;
                                                        if (Is_Edit)
                                                        {
                                                            selected = valItemArr[1] == Model.fields[item.name];
                                                        }
                                                        else
                                                        {
                                                            selected = valItemArr[1] == item.default_value;
                                                        }
                                                        @Html.RadioButton("field_control_" + item.name, valItemArr[1], selected, new { title = valItemArr[0] })
                                                    }
                                                }
                                            }
                                            <span class="Validform_checktip">@item.valid_tip_msg</span>
                                        </div>
                                    </div>
                                    break;
                                case "multi-checkbox"://多项多选
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">@item.title</label>
                                        <div class="layui-input-block">
                                            @{
                                                string[] valArr2 = item.item_option.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                                                string[] selValArr2 = Is_Edit ? Model.fields[item.name].Split(',') : item.default_value.Split(',');
                                                for (int i = 0; i < valArr2.Length; i++)
                                                {
                                                    string[] valItemArr2 = valArr2[i].Split('|');
                                                    if (valItemArr2.Length == 2)
                                                    {
                                                        bool selected2 = selValArr2.Contains(valItemArr2[1]);
                                                        <input id="field_control_@item.name" name="field_control_@item.name" @(selected2?"checked":"") title="@valItemArr2[0]" type="checkbox" value="@valItemArr2[1]">
                                                    }
                                                }
                                            }
                                            <span class="Validform_checktip">@item.valid_tip_msg</span>
                                        </div>
                                    </div>
                                    break;
                                case "similar"://同类选择
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">@item.title</label>
                                        <div class="layui-input-block">
                                            <a class="layui-btn layui-btn-primary icon-btn" href="javascript:;" onclick="showChooseDialog(this,'field_control_@item.name')"><i class="iconfont icon-add"></i> 选择</a>
                                            <div class="select_list">
                                                <table id="field_table_tonglei" cellpadding="0" cellspacing="0" class="listTable">
                                                    @{
                                                        if (Is_Edit)
                                                        {
                                                            if (Model.fields.ContainsKey(item.name))
                                                            {
                                                                string value = Model.fields[item.name];
                                                                if (value != "")
                                                                {
                                                                    DataTable dt = new DTcms.BLL.article().GetList(channel_id, 20, string.Format("id in ({0})", value), "id desc").Tables[0];
                                                                    foreach (DataRow dr in dt.Rows)
                                                                    {
                                                                        <tr class="data">
                                                                            <td><input type="hidden" name="field_control_@item.name" value="@dr["id"].ToString()">@dr["id"].ToString()</td>
                                                                            <td>@dr["title"].ToString()</td>
                                                                            <td><a href="javascript:;" onclick="remoreThis(this)">删除</a></td>
                                                                        </tr>
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    break;
                            }
                        }
                    </div>
                }
                <!-- /扩展选项 -->
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">调用别名</label>
                        <div class="layui-input-block">
                            @Html.TextBox("call_index", Model.call_index, new { @class = "input normal", datatype = @"/^\s*$|^[a-zA-Z0-9\-\_]{2,50}$/", sucmsg = " " })
                            <span class="Validform_checktip">*别名访问，非必填，不可重复</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">URL链接</label>
                        <div class="layui-input-block">
                            @Html.TextBox("link_url", Model.link_url, new { @class = "input normal", maxlength = "255" })
                            <span class="Validform_checktip">填写后直接跳转到该网址</span>
                        </div>
                    </div>
                    <!-- 信息来源 -->
                    @{
                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "source"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_source", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input normal" })
                                    @Html.Raw(Utils.ShowDropDownList(siteConfig.source, "field_control_source"))
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                    }
                    <!-- /信息来源 -->
                    <!-- 文章作者 -->
                    @{
                        findItem = sysFieldList.Find(delegate (DTcms.Model.article_attribute_field item) { return item.name == "author"; });
                        if (findItem != null)
                        {
                            <div class="layui-form-item">
                                <label class="layui-form-label">@findItem.title</label>
                                <div class="layui-input-block">
                                    @Html.TextBox("field_control_author", Is_Edit && Model.fields.ContainsKey(findItem.name) ? Model.fields[findItem.name] : findItem.default_value, new { @class = "input normal", datatype = "s0-50", sucmsg = " " })
                                    @Html.Raw(Utils.ShowDropDownList(siteConfig.author, "field_control_author"))
                                    <span class="Validform_checktip">@findItem.valid_tip_msg</span>
                                </div>
                            </div>
                        }
                    }
                    <!-- /文章作者 -->

                    <div class="layui-form-item">
                        <label class="layui-form-label">内容摘要</label>
                        <div class="layui-input-block">
                            @Html.TextArea("zhaiyao", Model.zhaiyao, new { @class = "input", datatype = "*0-255", sucmsg = " " })
                            <span class="Validform_checktip">不填写则自动截取内容前255字符</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容描述</label>
                        <div class="layui-input-block">
                            @Html.TextArea("content", Model.content, new { style = "height:300px; width:100%;", @class = "editor" })
                        </div>
                    </div>
                </div>
                @if (channelModel.is_attribute == 1)
                {
                    <div class="layui-tab-item">
                        <div class="layui-form-item">
                            <label class="layui-form-label">详细参数</label>
                            <div class="layui-input-block">
                                <a class="layui-btn layui-btn-primary icon-btn" onclick="addAttribute()"><i class="iconfont icon-add"></i> 增加一行</a>
                                <div id="showAttributeList">
                                    <ul class="argument" id="addcloumn">
                                        @if (Model.attribute != null)
                                        {
                                            foreach (var item in Model.attribute)
                                            {
                                                <li>
                                                    <input name="hid_attribute_name" type="text" class="input small" placeholder="名称" value="@item.title" />
                                                    <input name="hid_attribute_value" type="text" class="input normal" placeholder="内容" value="@item.value" />
                                                    <a href="javascript:;" onclick="delAttributeNode(this);" class="del" title="删除"><i class="iconfont icon-remove"></i></a>
                                                </li>
                                            }
                                        }
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                }
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO标题</label>
                        <div class="layui-input-block">
                            @Html.TextBox("seo_title", Model.seo_title, new { @class = "input normal", datatype = "*0-100", sucmsg = " ", maxlength = "255" })
                            <i class="layui-icon layui-icon-tips" lay-tips="一般不超过80个字符，为空时系统自动构成 " lay-direction="2"></i>
                            <span class="Validform_checktip">255个字符以内</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO关健字</label>
                        <div class="layui-input-block">
                            @Html.TextArea("seo_keywords", Model.seo_keywords, new { @class = "input", datatype = "*0-255", sucmsg = " " })
                            <i class="layui-icon layui-icon-tips" lay-tips="一般不超过100个字符，多个关键词请用英文逗号（,）隔开，建议3到5个关键词。" lay-direction="2"></i>
                            <span class="Validform_checktip">以“,”逗号区分开，255个字符以内</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO描述</label>
                        <div class="layui-input-block">
                            @Html.TextArea("seo_description", Model.seo_description, new { @class = "input", datatype = "*0-255", sucmsg = " " })
                            <i class="layui-icon layui-icon-tips" lay-tips="一般不超过200个字符，不填写时系统自动提取正文的前200个字符" lay-direction="2"></i>
                            <span class="Validform_checktip">255个字符以内</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--/内容-->
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-wrap">
            <button class="layui-btn icon-btn" id="btnSubmit"><i class="layui-icon layui-icon-ok"></i>提交保存</button>
            <button class="layui-btn layui-btn-warm icon-btn" name="btnReturn" onclick="javascript:history.back(-1);"><i class="layui-icon layui-icon-return"></i>返回上一页</button>
        </div>
    </div>
    <!--/工具栏-->
</form>
@section Scripts{
    <script type="text/javascript" src="/scripts/libs/js/uploader.js"></script>
    <script type="text/javascript">
        layui.use(['validform','jqueryform', 'element', 'cascadeSelect','laydate','tagsInput','fileChoose'], function () {
            var form = layui.form, cascadeSelect = layui.cascadeSelect, laydate = layui.laydate, admin = layui.admin,fileChoose=layui.fileChoose;
            cascadeSelect.init('category_id', false);
            cascadeSelect.init('field_control_provinceid', false);
            $(".rule-date-input").each(function(){
                laydate.render({
                    elem: this
                    ,type: 'datetime'
                });
            })
            $('#tags').tagsInput({skin: 'tagsinput-default'});
            $('.choose-pick').click(function () {
                var obj = $(this);
                fileChoose.open({
                    fileUrl: '',
                    listUrl: '/admin_ajax/files',
                    num: 1,
                    dialog: {
                        offset: '60px'
                    },
                    onChoose: function (res) {
                        if (res[0].type != "file") {
                            layer.msg('我只让你选择图片格式的文件', { icon: 2, time: 2000 }, function () { });
                            return;
                        }
                        obj.siblings(".upload-path").val(res[0].url);
                        obj.siblings(".layer-photos").show().find("img").attr("src", res[0].url);
                    }
                });
            });
            //操作类型
            var Control_Type = "@ViewBag.action";

            //初始化表单验证
            $("#form1").initValidform('#btnSubmit', 1);

            //封面
            $(".upload-cover").InitUploader({ cover: true, channel:@channel_id,sendurl: "/upload_ajax/action", swf: "/scripts/libs/module/uploader/uploader.swf" });
            //初始化上传控件
            $(".upload-img").InitUploader({ sendurl: "/upload_ajax/action", swf: "/scripts/libs/module/uploader/uploader.swf" });
            $(".upload-video").InitUploader({ btntext: "上传视频",sendurl: "/upload_ajax/action", swf: "/scripts/libs/module/uploader/uploader.swf", type:2, chunked: true });
            $(".upload-album").InitUploader({ btntext: "批量上传", multiple: true, water: true, channel:@channel_id, thumbnail: true, sendurl: "/upload_ajax/action", swf: "/scripts/libs/module/uploader/uploader.swf" });

            form.on('select(InValue)', function (data) {
                $(data.elem).prev().val(data.value);
            });
            $('#btnMap').click(function () {
                admin.chooseLocation({
                    needCity: true,
                    onSelect: function (res) {
                        layer.msg(JSON.stringify(res), {icon: 1});
                    }
                });
            });

            //初始化编辑器
            $(".editor").each(function (i) {
                var objId = $(this).attr("id");
                if (objId != "undefined") {
                    var editor = UE.getEditor(objId, {
                        serverUrl: '/upload_ajax/action',
                        initialFrameWidth: '100%',
                        initialFrameHeight: 350
                    });
                }
            });
            $(".editor-mini").each(function (i) {
                var objId = $(this).attr("id");
                if (objId != "undefined") {
                    var editorMini = UE.getEditor(objId, {
                        serverUrl: '/upload_ajax/action',
                        initialFrameWidth: '100%',
                        initialFrameHeight: 250,
                        toolbars: [['FullScreen', 'Source', 'bold', 'italic', 'underline', 'test', 'fontfamily', 'fontsize', 'forecolor', 'backcolor', 'insertimage', '|', 'insertorderedlist', 'insertunorderedlist', 'indent', 'justifyleft', 'justifycenter', 'justifyright', 'removeformat', 'help']],
                        elementPathEnabled: false,
                        wordCount: false
                    });
                }
            });

            //设置封面图片的样式
            $(".photo-list ul li .img-box img").each(function () {
                if ($(this).attr("src") == $("#hidFocusPhoto").val()) {
                    $(this).parent().addClass("selected");
                }
            });

            //创建上传附件
            $(".attach-btn").click(function () {
                showAttachDialog();
            });

            //创建视频在线观看
            $("#video_view").click(function () {
                var video_url = $("#field_control_video_src").val();
                if (video_url == "") {
                    layer.msg("没有播放视频源地址！");
                    return false;
                }
                showvideoDialog(video_url);
            });

            //创建视频在线观看
            $(".spec-btn").click(function () {
                showSpecDialog();
            });

            //赋值规格市场价格
            $("#field_control_market_price").blur(function () {
                $("#div_spec__container").find("input[name='spec_market_price']").val($(this).val());
            });

            //赋值规格销售价格
            $("#field_control_sell_price").blur(function () {
                $("#div_spec__container").find("input[name='spec_sell_price']").val($(this).val());
            });
        });
        //创建同类选择窗口
        function showChooseDialog(obj, sidername) {
            layer.open({
                type: 2,
                area: ['800px', '750px'],
                title: "相关信息选择",
                maxmin: true,
                content: '../dialog/dialog_choose?channel_id=@channel_id&sidername=' + sidername,
                btn: ["确定",'关闭'],
                btn1: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var liHtml = iframeWin.submitTbody();
                    if (liHtml.length > 0) {
                        var box = $(obj).parent().parent();
                        //判断是否存在tbody
                        if (box.find("tbody").length <= 0) {
                            box.find("table").html("<tbody></tbody>")
                        }
                        box.find("tbody").append(liHtml);
                        layer.close(index);
                    }
                },
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                },
                cancel: function (index, layero) { }
            });
        }
        //清除选择
        function remoreThis(obj) {
            $(obj).parent().parent().remove();
        }

        //初始化附件窗口
        function showAttachDialog(obj) {
            var objNum = arguments.length;
            layer.open({
                type: 2,
                area: ['500px', '290px'],
                title: "上传附件",
                maxmin: true,
                content: '../dialog/dialog_attach',
                btn: ["确定",'关闭'],
                btn1: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var liHtml = iframeWin.execAttachHtml(obj);
                },
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    //检查是否修改状态
                    iframeWin.submitValue(obj);
                },
                cancel: function (index, layero) { }
            });
        }

        //删除附件节点
        function delAttachNode(obj) {
            $(obj).parent().remove();
        }

        //视频观看窗口
        function showvideoDialog(url) {
            layer.open({
                type: 2,
                area: ['830px', '560px'],
                title: "视频观看",
                maxmin: true,
                content: '../dialog/dialog_video?video_src='+url,
                cancel: function (index, layero) { }
            });
        }

        //初始化规格窗口
        function showSpecDialog() {
            layer.open({
                type: 2,
                area: ['510px', '400px'],
                title: "商品规格",
                maxmin: true,
                content: '../dialog/dialog_article_spec?channel_id=@ViewBag.channel_id',
                btn: ["确定",'关闭'],
                btn1: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    iframeWin.createSpecHtml($("#item_box"));
                },
                success: function (layero, index) {
                    layer.iframeAuto(index);
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    //将容器对象传进去
                    iframeWin.submitValue($("#item_box"));
                },
                cancel: function (index, layero) { }
            });
        }

        //初始化会员组价格窗口
        function showPriceDialog(obj) {
            layer.open({
                type: 2,
                area: ['400px', '320px'],
                title: "会员组价格",
                maxmin: true,
                content: '../dialog/dialog_group_price',
                btn: ["确定",'关闭'],
                btn1: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    iframeWin.setGroupPrice(obj);
                },
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    iframeWin.submitValue(obj);
                },
                cancel: function (index, layero) { }
            });
        }

        //计算出最小的市场价格
        function countMarketPrice(obj) {
            var objName = $(obj).attr("name");
            var minValue = parseFloat($(obj).val());
            $("input[name='" + objName + "']").each(function () {
                if ($(this).val().length > 0) {
                    if (parseFloat($(this).val()) < minValue) {
                        minValue = parseFloat($(this).val());
                    }
                }
            });
            $("#field_control_market_price").val(minValue);
        }

        //计算最小的销售价格
        function countSellPrice(obj) {
            var objName = $(obj).attr("name");
            var minValue = parseFloat($(obj).val());
            $("input[name='" + objName + "']").each(function () {
                if ($(this).val().length > 0) {
                    if (parseFloat($(this).val()) < minValue) {
                        minValue = parseFloat($(this).val());
                    }
                }
            });
            $("#field_control_sell_price").val(minValue);
        }

        //计算库存总数量
        function countStockQuantity(obj) {
            var objName = $(obj).attr("name");
            var countValue = 0;
            $("input[name='" + objName + "']").each(function () {
                if ($(this).val().length > 0) {
                    countValue += parseFloat($(this).val());
                }
            });
            $("#field_control_stock_quantity").val(countValue);
        }

        //添加扩展参数一行
        function addAttribute() {
            var liHtml = '<li>'
                + '<input name="hid_attribute_name" class="input small" placeholder="名称" type="text" />'
                + '<input name="hid_attribute_value" class="input normal" placeholder="内容" type="text" />'
                + '<a href="javascript:;" onclick="delAttributeNode(this);" class="del" title="删除"><i class="iconfont icon-remove"></i></a>'
                + '</li>';
            $("#showAttributeList").children("ul").append(liHtml);
        }

        //删除附件节点
        function delAttributeNode(obj) {
            $(obj).parent().remove();
        }
    </script>
}
